#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<algorithm>

using namespace std;

typedef long long LL;

const int N = 100010;

int n, m;
int a[N], cnt[N];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)   scanf("%d", &a[i]);
    scanf("%d", &m);
    while (m--)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        cnt[l]++;
        cnt[r + 1]--;
    }

    for (int i = 1; i <= n; i++)   cnt[i] += cnt[i - 1];

    LL bef = 0;
    for (int i = 1; i <= n; i++)   bef += (LL)a[i] * cnt[i];
    sort(a + 1, a + 1 + n), sort(cnt + 1, cnt + n + 1);
    LL sum = 0;
    for (int i = 1; i <= n; i++)   sum += (LL)cnt[i] * a[i];
    printf("%lld\n", sum - bef);
    return 0;
}